package com.ejuornal.action;

import java.util.Date;
import java.util.List;

import com.ejuornal.bean.Editor;
import com.ejuornal.bean.User;
import com.ejuornal.bean.vo.EUserPeriodical;
import com.ejuornal.service.EditorService;
import com.ejuornal.service.EditorVoService;
import com.ejuornal.service.UserService;
import com.ejuornal.springutil.SpringUtil;

public class EditorAction extends BaseAction<Editor>{
	private static final long serialVersionUID = 1L;
	private Editor editor;
	private EUserPeriodical eUserPeriodical;
	private List<EUserPeriodical> editorVOList;
	private EditorVoService editorVoService;
	private EditorService editorService;
	private String value;//传的单个参数值有value接收
	private String userIdStr;//会员id
	private UserService userService;
	/**
	 * 根据主编id获取所管理的所有期刊对应的编辑
	 * @author lwf
	 * @return editorVOList
	 */
	public String getAllEditorByChiefId(){
		int editorChiefId = super.getUserIdBySession();//由session获得
		editorVoService = (EditorVoService) SpringUtil.getBean("editorVoService");
		editorVOList = editorVoService.findByEditorChiefId(editorChiefId);
		return "success";
	}
	
	/**
	 * 删除编辑--事实是修改编辑状态
	 * @author lwf
	 * @return
	 */
	public String deleteEditor(){
		int editorid = Integer.parseInt(value);
		editorService = (EditorService) SpringUtil.getBean("editorService");
		editor = new Editor();
		editor.setEditorId(editorid);
		String states = "0";//任职状态 0-离职 1-任职
		editor.setStatus(states);
		editorService.update(editor);
		User user = new User();
		System.out.println(userIdStr);
		int userId = Integer.parseInt(userIdStr);
		user.setUserId(userId);
		user.setRoleId(2);//离职后  会员表状态改为 2--会员
		userService.updateRoleIdOnly(user);
		return "success";
	}
	
	/**
	 * 根据期刊id获取该期刊的所有编辑
	 * @return editorVOList
	 */
	public String getEditorByPeriodicalId(){
		int periodicalid =Integer.parseInt(value);
		editorVoService = (EditorVoService) SpringUtil.getBean("editorVoService");
		editorVOList = editorVoService.findByPeriodicalId(periodicalid);
		return "success";
	}
	
	/**
	 * 添加编辑
	 * @author lwf
	 * @return
	 */
	public String addEditor(){
		editorService = (EditorService) SpringUtil.getBean("editorService");
		userService = (UserService) SpringUtil.getBean("userService");
		editor.setWorkDate(new Date());
		editor.setStatus("1");//编辑 在职状态为1   离职状态为0
		editorService.add(editor);
		User user = new User();
		user.setUserId(editor.getUserId());
		user.setRoleId(5);//编辑的roleId为5
		userService.updateRoleIdOnly(user);
		return "success";
	}
	
	public List<EUserPeriodical> getEditorVOList() {
		return editorVOList;
	}

	public void setEditorVOList(List<EUserPeriodical> editorVOList) {
		this.editorVOList = editorVOList;
	}

	public EditorVoService getEditorVoService() {
		return editorVoService;
	}
	public void setEditorVoService(EditorVoService editorVoService) {
		this.editorVoService = editorVoService;
	}

	public EditorService getEditorService() {
		return editorService;
	}

	public void setEditorService(EditorService editorService) {
		this.editorService = editorService;
	}

	public Editor getEditor() {
		return editor;
	}

	public void setEditor(Editor editor) {
		this.editor = editor;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public EUserPeriodical geteUserPeriodical() {
		return eUserPeriodical;
	}

	public void seteUserPeriodical(EUserPeriodical eUserPeriodical) {
		this.eUserPeriodical = eUserPeriodical;
	}

	public String getUserIdStr() {
		return userIdStr;
	}

	public void setUserIdStr(String userIdStr) {
		this.userIdStr = userIdStr;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
}
